// Telnet Client

import java.net.*;
import java.io.*;

public class TelnetClient {
    public static void main(String args[]) throws Exception {
        Socket soc = new Socket("127.0.0.1", 5217);
        String LoginName;
        String Password;
        String Command;

        DataInputStream din = new DataInputStream(soc.getInputStream());
        DataOutputStream dout = new DataOutputStream(soc.getOutputStream());
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        System.out.println("客户端启动！！！");
        System.out.println("Welcome to Telnet Client");
        System.out.println("Your Credential Please...");
        System.out.print("Login Name :");

        LoginName = br.readLine();

        System.out.print("Password :");
        Password = br.readLine();

        dout.writeUTF(LoginName);
        dout.writeUTF(Password);

        if (din.readUTF().equals("ALLOWED")) {
            do {
                System.out.print(">:");
                Command = br.readLine();
                dout.writeUTF(Command);
                if (!Command.equals("quit")) {
                    System.out.println(din.readUTF());
                } else {
                    String arr = din.readUTF();
                    System.out.println(arr);
                }
            } while (!Command.equals("quit"));
        } else {
            System.out.println("用户名或密码错误");
        }
        soc.close();
    }
}
